﻿@using RechercheEmplois.Models;
@using Microsoft.AspNet.Identity;
@model RechercheEmplois.ViewModel.ManageUserDataVM
@{
    ViewBag.Title = "Manage Compte";
}

<h2>Bienvenue @Model.User.Prenom @Model.User.Nom.</h2>
<p>Vous vous avez connecté à <strong>@Model.User.GroupUtilisateur.Libelle</strong>.</p>

<p class="text-success">@ViewBag.StatusMessage</p>
<div class="panel panel-default" id="panel1">
    <div class="panel-heading">
        <h4 class="panel-title text-danger">
            <a data-toggle="collapse" data-target="#collapseOne"
               href="#collapseOne">
                Modifier votre informations
            </a>
        </h4>
    </div>
    <div id="collapseOne" class="panel-collapse collapse in">
        <div class="panel-body">
            <div class="row">
                <div class="col-md-12">
                    @if (ViewBag.HasLocalPassword)
                    {
                        @Html.Partial("_ChangePasswordPartial", Model.ManageUserViewModel)
                    }
                    else
                    {
                        @Html.Partial("_SetPasswordPartial")
                    }
                </div>
            </div>
        </div>
    </div>
</div>
<hr />

@if (Model.UserType == "Administrator")
{
    <div class="row text-center">
    <h4>Les fonctions gérées</h4>
        @Html.ActionLink("Gérer les domaines", "Index", "Domaine", null, new { @class = "btn btn-default" })
        @Html.ActionLink("Gérer les utilisateurs", "Index", "Utilisateur", null, new { @class = "btn btn-primary" })
        @Html.ActionLink("Gérer les villes", "Index", "Ville", null, new { @class = "btn btn-success" })
        @Html.ActionLink("Gérer les provines", "Index", "Provine", null, new { @class = "btn btn-info" })
    </div>
    <hr />
}

<div class="row">
    @if (Model.UserType == "Internaute")
    {
        <div class="col-md-12 panel panel-default">
            <h4 class="text-center">Les sauvegardes <span class="badge">@Model.User.Sauvegardes.Count()</span></h4>
            @foreach (var item in Model.User.Sauvegardes)
            {
                <div class="panel panel-info">
                    <div class="panel-heading">@Html.ActionLink(@item.Offre.Libelle, "Details", "Offre", new { id = item.OffreID }, new { @class = "h5" })</div>
                    <div class="panel-body">
                        @item.Offre.Description
                        <blockquote>
                            <small>@item.TempSauvegarde</small>
                        </blockquote>
                    </div>
                    <div class="panel-footer">
                        <a class="btn-xs btn-warning" onclick="supprimerOffre(@item.SauvegardeID);">Supprimer</a>
                        @Html.ActionLink("Postuler", "Create", "Postuler", new { offreID = item.OffreID }, new { @class = "btn-xs btn-success" })
                    </div>
                </div>
            }
        </div>
    }
    else if (Model.UserType == "Recruiteur")
    {
        <div class="col-md-12 panel panel-default">
            <h4 class="text-center">Les offres déposés <span class="badge">@Model.User.Deposes.Count()</span></h4>
            @Html.ActionLink("Creer nouveau offre", "Create", "Offre", null, new { @class = "btn btn-primary" })
            @foreach (var item in Model.User.Deposes)
            {
                <div class="panel panel-info">
                    <div class="panel-heading">@Html.ActionLink(@item.Libelle, "Details", "Offre", new { id = item.ID }, new { @class = "h5" })</div>
                    <div class="panel-body">
                        <dl class="dl-horizontal">
                            <dt>Domaine</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Domaine.Libelle)</dd>
                            <dt>Localtion</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Ville.Libelle)</dd>
                            <dt>Job Type</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Type)</dd>
                            <dt>Descriptions</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Description)</dd>
                            <dt>Tags</dt>
                            <dd>
                                @foreach (var motcle in item.MotCles)
                                {
                                    <span class="label label-primary">@motcle.Libelle</span>
                                }
                            </dd>
                        </dl>
                    </div>
                    <div class="panel-footer">
                        @Html.ActionLink("Modifier", "Edit", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-primary" })
                        @Html.ActionLink("Supprimer", "Delete", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-success" })
                    </div>
                </div>
            }
        </div>
    }
    else //Administrator
    {
        <div class="col-md-12 panel panel-default">
            <h4 class="text-center">Les offres disponibles<span class="badge">@Model.Offres.Count()</span></h4>
            @foreach (var item in Model.Offres)
            {
                <div class="panel panel-default">
                    <div class="panel-heading">@Html.ActionLink(@item.Libelle, "Details", "Offre", new { id = item.ID }, new { @class = "h5" })</div>
                    <div class="panel-body">
                        <dl class="dl-horizontal">
                            <dt>Domaine</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Domaine.Libelle)</dd>
                            <dt>Localtion</dt>
                            <dt>Descriptions</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Description)</dd>
                            <dt>Recruiteur</dt>
                            <dd>@Html.DisplayFor(modelItem => item.Recruiteur.Nom)</dd>
                            <dt>Valide? </dt>
                            <dd>@Html.DisplayFor(modelItem => item.Valide)</dd>
                        </dl>
                    </div>
                    <div class="panel-footer">
                        @if (item.Valide == 0)
                        {
                            @Html.ActionLink("Valider", "Valider", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-danger" })
                        }
                        else
                        {
                            @Html.ActionLink("Dé-valider", "Valider", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-danger" })
                        }
                        @Html.ActionLink("Modifier", "Edit", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-primary" })
                        @Html.ActionLink("Supprimer", "Delete", "Offre", new { id = item.ID }, new { @class = "btn-sm btn-success" })
                    </div>
                </div>
            }
        </div>
    }
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script type="text/javascript">
    //Sauvegarder buttons click
    function saveOffre(id) {
        // e.preventDefault(); use this or return false
        $.ajax({
            url: "/Sauvegarde/Create",
            type: "post",
            data: "OffreID=" + id,
            success: function (result) {
                var response;
                if (result == 1) {
                    response = "Offre est sauvé succès!";
                }
                else if (result == 0) {
                    response = "Offre a été déjà sauvé!";
                } else {
                    response = "Utilisateur non identifié!";
                }
                var url = '/Offre/GetMessage?title=SaveInformation&body=' + encodeURI(response);
                $("#myModal").on("show.bs.modal", function (e) {
                    $(e.target).find('.modal-content').load(url);
                });
                $('#myModal').modal('show');
                $('#myModal').on('hidden.bs.modal', function () {
                    if (result == 1)
                        window.location.reload();
                });
            },
            error: function () {
                alert("technique failure!");
            }
        });
    }
    //Supprimer offre sauvegarde click
    function supprimerOffre(id) {
        // e.preventDefault(); use this or return false
        $.ajax({
            url: "/Sauvegarde/Delete",
            type: "post",
            data: "id=" + id,
            success: function (result) {
                var response = "";
                if (result == -1) {
                    response = "Ne trouver pas l'offre qui a besoin de supprimer!";
                }
                else if (result == 0) {
                    response = "L'offre sauvegardé a été supprimé!";
                }
                var url = '/Offre/GetMessage?title=SaveInformation&body=' + encodeURI(response);
                $("#myModal").on("show.bs.modal", function (e) {
                    $(e.target).find('.modal-content').load(url);
                });
                $('#myModal').modal('show');
                $('#myModal').on('hidden.bs.modal', function () {
                    if (result == 0)
                        reloadPage();
                });
            },
            error: function () {
                alert("technique failure!");
            }
        });
    }
</script>
